package jdbc.homework01;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import java.util.Scanner;

public class StudentMessge02 {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		Connection con = DbUtil.getConnection();
		Statement st = null;
		PreparedStatement ps = null;
		ResultSet rs = null;
		try {

			System.out.println("请输入学生学号：");
			int stuno = in.nextInt();
			System.out.println("请输入学生姓名：");
			String sname = in.next();
			System.out.println("请输入学生性别：");
			String sex = in.next();
			System.out.println("请输入学生电话：");
			String tel = in.next();
			System.out.println("请输入学生QQ：");
			String qq = in.next();
			System.out.println("请输入学生微信：");
			String wechat = in.next();
			System.out.println("请输入学生年级号：");
			int gradeid = in.nextInt();
			System.out.println("请输入学生入学时间：");
			String enterdate = in.next();
			System.out.println("请输入学生城市：");
			String fromcity = in.next();
			System.out.println("请输入学生入学时间：");
			String brithday = in.next();
			System.out.println("请输入学生地址：");
			String address = in.next();
			System.out.println("请输入学生密码：");
			String pass = in.next();
			String sql = "insert into s_student values(?,?,?,?,?,?,?,?,?,?,?,?)";
			ps = con.prepareStatement(sql);
			ps.setInt(1, stuno);
			ps.setString(2, sname);
			ps.setString(3, sex);
			ps.setString(4, tel);
			ps.setString(5, qq);
			ps.setString(6, wechat);
			ps.setInt(7, gradeid);
			ps.setString(8, enterdate);
			ps.setString(9, fromcity);
			ps.setString(10, brithday);
			ps.setString(11, address);
			ps.setString(12, pass);
			int r = ps.executeUpdate();
			System.out.println("插入了" + r + "条信息");
		} catch (SQLException e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} finally {
			DbUtil.close(con, st, rs, ps);
		}

	}

}
